package com.pdsu.graduation_design.views;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.pdsu.graduation_design.MainActivity;
import com.pdsu.graduation_design.R;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

public class My_FeadBack_Activity extends AppCompatActivity {

    EditText feedback_message_et,feedback_fname_et;
    TextView feedback_submit_tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_fead_back);
        init();
    }
    void init(){
        feedback_message_et= findViewById(R.id.feedback_message_et);
        feedback_submit_tv=findViewById(R.id.feedback_submit_tv);
        feedback_fname_et=findViewById(R.id.feedback_fname_et);
        feedback_submit_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (feedback_message_et.getText().toString().length()<10||feedback_fname_et.getText().toString().length()<10){
                    Toast.makeText(getApplicationContext(), "请输入要反馈的信息，且长度不少于10个字", Toast.LENGTH_SHORT).show();
                }else {
                    RequestParams requestParams =new RequestParams(MainActivity.URL+"/user/addFeedBack");
                    requestParams.addParameter("msg",feedback_message_et.getText().toString());
                    requestParams.addParameter("fname",feedback_fname_et.getText().toString());
                    requestParams.addParameter("uid",MainActivity.user_admin.getUid());
                    requestParams.addParameter("phone",MainActivity.user_admin.getPhone());
                    x.http().post(requestParams, new Callback.CommonCallback<String>() {
                        @Override
                        public void onSuccess(String result) {

                            Toast.makeText(getApplicationContext(), "反馈成功", Toast.LENGTH_SHORT).show();
                            finish();
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {

                        }

                        @Override
                        public void onCancelled(CancelledException cex) {

                        }

                        @Override
                        public void onFinished() {

                        }
                    });

                }
            }
        });
    }

}